/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package schtohan.managedbeans;

import java.util.Collections;
import java.util.Comparator;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import schtohan.entities.Journey;
import schtohan.entities.Stop;

/**
 *
 * @author Schtohan
 */
@ManagedBean
@RequestScoped
public class journeyBean {

    private Journey selectedJourney;

    public journeyBean() {
        
    }
    
    public String viewJourney()
    {
        sortStops(selectedJourney);
        return "journey";
    }

    public Journey getSelectedJourney() {
        return selectedJourney;
    }

    public void setSelectedJourney(Journey selectedJourney) {
        this.selectedJourney = selectedJourney;
    }

    private void sortStops(Journey selectedJourney) {
        Collections.sort(selectedJourney.getStops(), new Comparator<Stop>() {
 
            @Override
            public int compare(Stop s1, Stop s2) {
                return s1.getStopNr().compareTo(s2.getStopNr());
            }
        });
    }

}
